﻿/*-------------------------------------------------------------------------
 * 版权所有：	黑客马拉松
 * 作者：		罗毅
 * 联系方式：	whluoyi@gmail.com
 * 创建时间：	2016/10/29 11:23:16
 * 版本号：		v1.0
 * 用途描述：	SuperMarieApi业务对象
 *  -------------------------------------------------------------------------*/

namespace SuperMarieApi.App.Controllers.Biz
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    using SuperMarieApi.App.Controllers.Entity;
    using SuperMarieApi.App.Controllers.Framework.DataAccess;
    using SuperMarieApi.App.Controllers.Tool.Extensions;

    public class MySessionBiz
    {
        /// <summary>
        /// 获取MySession列表
        /// </summary>
        /// <returns></returns>
        public static List<MySessionEntity> GetMySessionList()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MySessionList");
            List<MySessionEntity> lists = cmd.ExecuteEntityList<MySessionEntity>();
            return lists;
        }

        /// <summary>
        /// 获取MySession列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMySessionData()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MySessionList");
            return cmd.ExecuteDataSet().Tables[0];
        }

        /// <summary>
        /// 获取MySession详情
        /// </summary>
        /// <returns></returns>
        public static MySessionEntity GetMySessionObj(int MySession_ID)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MySession");
            cmd.SetParameterValue("@MySession_ID", MySession_ID);
            MySessionEntity obj = cmd.ExecuteEntity<MySessionEntity>();
            return obj;
        }

        /// <summary>
        /// 更新MySession详情
        /// </summary>
        /// <returns></returns>
        public static int SetMySessionObj(MySessionEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Set-MySession");
            cmd.SetParameterValue("@MySession_ID", obj.MySession_ID);
            cmd.SetParameterValue("@MyImg_ID", obj.MyImg_ID);
            cmd.SetParameterValue("@session_id", obj.session_id);
            cmd.SetParameterValue("@url", obj.url);
            cmd.SetParameterValue("@img_id", obj.img_id);
            cmd.SetParameterValue("@face_id", obj.face_id);
            cmd.SetParameterValue("@attribute", obj.attribute);
            cmd.SetParameterValue("@gender", obj.gender);
            cmd.SetParameterValue("@age", obj.age);
            cmd.SetParameterValue("@race", obj.race);
            cmd.SetParameterValue("@smiling", obj.smiling);
            cmd.SetParameterValue("@glass", obj.glass);
            cmd.SetParameterValue("@pose", obj.pose);
            cmd.SetParameterValue("@DetectResult", obj.DetectResult);
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 插入MySession详情
        /// </summary>
        /// <returns></returns>
        public static int InsertMySessionObj(MySessionEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Insert-MySession");
            cmd.SetParameterValue("@MyImg_ID", obj.MyImg_ID);
            cmd.SetParameterValue("@session_id", obj.session_id);
            cmd.SetParameterValue("@url", obj.url);
            cmd.SetParameterValue("@img_id", obj.img_id);
            cmd.SetParameterValue("@face_id", obj.face_id);
            cmd.SetParameterValue("@attribute", obj.attribute);
            cmd.SetParameterValue("@gender", obj.gender);
            cmd.SetParameterValue("@age", obj.age);
            cmd.SetParameterValue("@race", obj.race);
            cmd.SetParameterValue("@smiling", obj.smiling);
            cmd.SetParameterValue("@glass", obj.glass);
            cmd.SetParameterValue("@pose", obj.pose);
            cmd.SetParameterValue("@DetectResult", obj.DetectResult);
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            object identity = cmd.ExecuteScalar();
            if (identity == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(identity);
            }
        }

        /// <summary>
        /// 分页MySession数据列表
        /// </summary>
        /// <returns></returns>
        public static DataSet PageMySessionList(int pageSize, int pageIndex, string strWhere, string sortField = "MySession_ID", string sortOrder = "DESC")
        {
            if (!strWhere.SqlFilter_List())
            {
                return null;
            }
            string pagesort = "";
            string pagewhere = "";
            string pageindexsize = "";
            if (!string.IsNullOrEmpty(sortField.Trim()))
            {
                pagesort = "ORDER BY " + sortField + " " + sortOrder;
            }
            else
            {
                pagesort = "ORDER BY T.MySession_ID " + sortOrder;
            }
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                pagewhere = " WHERE " + strWhere;
            }
            pageindexsize = " WHERE TT.Row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize);
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Page-MySession");
            cmd.SetParameterValue("@pagesort", pagesort);
            cmd.SetParameterValue("@pagewhere", pagewhere);
            cmd.SetParameterValue("@pageindexsize", pageindexsize);
            return cmd.ExecuteDataSet();
        }
    }
}